using UnityEngine;

public class ShowAdsR : MonoBehaviour
{
	public static int apiLevelint = 1;

	private int count;

	private int cn;

	private void Awake()
	{
		if (UnityEngine.SceneManagement.SceneManager.GetActiveScene().name == "mainmenu")
		{
			cn = 4;
		}
		else
		{
			cn = 1;
		}
		if (PlayerPrefs.GetInt("tmp") != 7)
		{
			if (AdvertisementHandler.lastAdType != 1 && UnityEngine.SceneManagement.SceneManager.GetActiveScene().name == "mainmenu")
			{
				AdvertisementHandler.DisableAds();
				Invoke("Enable", 0.8f);
			}
			else
			{
				AdvertisementHandler.ShowAds();
			}
			Preload();
			count = PlayerPrefs.GetInt("Count2");
			count++;
			if (count > cn && Time.time - AdvertisementHandler.lastTime > (float)(40 + UnityEngine.Random.Range(0, 10)) && JavaMessageHandler.interstitialPreloaded)
			{
				ShowPreloaded();
				Invoke("Preload", 1f);
				AdvertisementHandler.lastTime = Time.time;
				count = 0;
			}
			if (count < 0)
			{
				count = 0;
			}
			PlayerPrefs.SetInt("Count2", count);
		}
	}

	private void ShowPreloaded()
	{
		AdvertisementHandler.ShowPreloadedInterstitial(rewarded: false);
		JavaMessageHandler.interstitialPreloaded = false;
	}

	private void Preload()
	{
		if (!JavaMessageHandler.interstitialPreloaded)
		{
			AdvertisementHandler.PreloadInterstitial();
		}
	}

	private void RefreshAd()
	{
		AdvertisementHandler.lastBannerTime = Time.time;
		AdvertisementHandler.RefreshAds();
	}

	private void Enable()
	{
		AdvertisementHandler.EnableAds2();
	}
}
